#ifndef INDEX_H
#define INDEX_H

#include <api/userapi.h>
#include <QLabel>
#include <QMainWindow>
#include <QMessageBox>
#include <QVariant>
#include <router/systemManager/userManager/usermanager.h>
#include <router/systemManager/userManager/edituserdlg.h>
#include <router/systemManager/userManager/usermanagerhidecolumndlg.h>
#include <router/systemManager/userManager/authroledlg.h>
#include <component/tagview.h>
namespace Ui {
class Index;
}

class Index : public QMainWindow
{
    Q_OBJECT

public:
    explicit Index(QWidget *parent = nullptr);
    ~Index();

protected:
    void keyPressEvent(QKeyEvent *event);

signals:
    void logout();
    void open();
    void stop();

    void sendParamToEditUserDlg(QList<TreeSelect> *deptTreeList,
                                QString initPassword,
                                QList<DictData> *dictDataList,
                                QList<DictData> *sexDataList);

private slots:
    void on_btn_test_clicked();

    void on_pushButton_baseInfo_clicked();

    void on_pushButton_resetPwd_clicked();

    void on_pushButton_saveBaseInfo_clicked();

    void on_lineEdit_phone_textChanged(const QString &arg1);

    void on_lineEdit_email_textChanged(const QString &arg1);

    void on_pushButton_savePwd_clicked();

    void on_lineEdit_oldPwd_textChanged(const QString &arg1);

    void on_lineEdit_newPwd_textChanged(const QString &arg1);

    void on_lineEdit_newPwd2_textChanged(const QString &arg1);

    void on_pushButton_hideRouter_clicked();

    void on_comboBox_userManager_pageItem_currentIndexChanged(int index);

    void on_btn_userManager_next_clicked();

    void on_btn_userManager_pervious_clicked();

    void on_lineEdit_userManager_gotoPage_returnPressed();

    void on_btn_userManager_hideSearch_clicked();

    void on_btn_userManager_refresh_clicked();

    void on_btn_userManager_search_clicked();

    void on_btn_userManager_reset_clicked();

    void on_lineEdit_userManager_deptName_textChanged(const QString &arg1);

    void on_btn_userManager_isHideColumn_clicked();

    void on_btn_userManager_add_clicked();

    void on_btn_userManager_modify_clicked();

    void on_btn_userManager_delete_clicked();

    void on_btn_userManager_export_clicked();

    void on_btn_userManager_import_clicked();


    void on_btn_countCode_clicked();

private:
    Ui::Index *ui;
    
    QObject *routerObj = nullptr;
    //放置tagview的布局
    QBoxLayout *tagLayout;
    QHash<int,QObject*> routerMap;
    QList<TagView*> tagList;
    int tagIndex = 0;

    QStringList userManagerTableColumn;
    //每页大小
    int userManagerPageSize = 10;
    int userManagerTotal;
    int userManagerCurrentPage = 1;
    int userManagerDeptId = 0;
    UserManagerHideColumnDlg *userManagerHideColumnDlg;
    //部门树
    QList<TreeSelect> *deptTreeList;
    //部门树槽
    QMetaObject::Connection connection;
    //部门树菜单
    UserManagerApi userManagerApi;
    UserManager userManager;
    //初始化用户管理页面
    void initUserManager();
    void setUserManagerPage(int pageNum,int pageSize);
    //状态
    QList<DictData> *dictDataList;
    //性别
    QList<DictData> *sexDataList;
    //更多按钮弹窗相关
    QDialog *moreDlg;

    //初始密码
    QString initPassword;
    //记录标签的数量
    QList<QWidget> *tagWidgets;
    //菜单弹窗
    QTreeWidget *treeWidget;
    //路由菜单json数组
    QJsonArray routerArr;
    //头像
    QPixmap avatar;
    QTimer *timer;
    //鼠标全局坐标
    QPoint mouseGlobalPos;
    UserApi userApi;
    Utils utils;
    User *user;
    //个人中心弹窗
    QDialog *dlg;
    QRegularExpression *rvalEmail;
    QRegularExpression *rvalPhone;

    // QAbstractItemModel *model;
    void init();
    //路由
    void getRouters();
    //插入tagView
    void insertTagView(int index,QString name,QModelIndex modelIndex);
    //个人信息
    void getInfo();
    //头像点击事件
    bool eventFilter(QObject *obj, QEvent *event);
    void userCenterDlg(QDialog *dlg);
    //初始化个人中心
    void initUserCenter();
    //treewidget点击事件
    void treeWidgetClicked();
    void btn_uploadAvatar_clicked();
    void setRouters(QJsonArray routerArr);
    //递归设置路由子菜单
    void setTreeRouters(QJsonArray *treeList,QTreeWidgetItem *menu);
    bool event(QEvent *event);
    void popMenu(int flag);
    void setTreePopMenu(QJsonArray *treeList,QTreeWidgetItem *menu);
    void routerJump(QTreeWidgetItem *item);
    void routerClick(int index,QString name);
    //递归设置部门树菜单
    void setTreeMenu(QList<TreeSelect> *treeList,QTreeWidgetItem *menu);

};

#endif // INDEX_H
